﻿using System.Linq.Expressions;
using Basic.FormDAL;
using Basic.FormModel.DB;
using Basic.FormRemoteModel.FormView.Model;
using WeDonekRpc.SqlSugar.VirtualQuery;

namespace Basic.FormCollect.lmpl
{
    internal class FormViewCollect : IFormViewCollect
    {
        private readonly IFormViewDAL _BaseDAL;

        public FormViewCollect ( IFormViewDAL baseDAL )
        {
            this._BaseDAL = baseDAL;
        }

        public long Add ( FormViewAdd data )
        {
            return this._BaseDAL.Add(data);
        }
        public DBFormView Get ( long id )
        {
            return this._BaseDAL.Get(id);
        }
        public DBFormView Find ( long formId )
        {
            return this._BaseDAL.Find<DBFormView>(a => a.FormId == formId);
        }
        public Result Find<Result> ( long formId ) where Result : class, new()
        {
            return this._BaseDAL.Find<Result>(a => a.FormId == formId);
        }
        public Result Find<Result> ( long formId, Expression<Func<DBFormView, Result>> selector )
        {
            return this._BaseDAL.Find<Result>(a => a.FormId == formId, selector);
        }
        public void Delete ( DBFormView source, string name )
        {
            this._BaseDAL.Delete(source, name);
        }
        public bool Update ( DBFormView source, FormViewSet set )
        {
            return this._BaseDAL.Update(source, set);
        }

        public void GenerateView ( DBFormView sour, string name, QueryStruct body )
        {
            this._BaseDAL.GenerateView(sour, name, body);
        }

        public bool CheckIsGenerate ( long formId )
        {
            return this._BaseDAL.Find(a => a.FormId == formId, a => a.IsGenerate);
        }
    }
}
